export default {
	setUserInfo(state, userInfo) {
		state.userInfo = userInfo;
		uni.setStorageSync('userInfo', userInfo);
	},
	showSidebar(state) {
		state.sidebar.visible = true
	},
	hideSidebar(state) {
		state.sidebar.visible = false
	},
	changeSideBarMenuOptions(state, menu) {
		state.sidebar.menu = menu;
	},
	setCartList(state, cartList) {
		state.cartList = cartList;
		uni.setStorageSync('cartList', cartList);
	},
	setReserveList(state, reserveList) {
		state.reserveList = reserveList;
		uni.setStorageSync('reserveList', reserveList);
	},
	setCartListStateKeep(state, cartListStateKeep) {
		state.cartListStateKeep = cartListStateKeep;
	},
	setReserveListStateKeep(state, reserveListStateKeep) {
		state.reserveListStateKeep = reserveListStateKeep;
	},
	setCarSelectedtList(state, setCartSelectedList) {
		state.cartSelectedList = setCartSelectedList;
	},
	setSidebarInfo(state, setSidebarInfo) {
		state.sidebarInfo = setSidebarInfo;
	},
	setCartGoodsList(state,goods) {//查询购物车是否存在该商品,如果不存在,添加.如果存在,return
		let cartGoodsList = state.cartGoodsList || [];
		if (cartGoodsList.findIndex(item=>item.id == goods.id)>=0) return false;
		else {
			let data = {
				id: goods.id,
				isPre: goods.isPre || 2,
				isDelete: goods.isDelete || 2,
				checked: goods.checked || true,
				number: goods.singleLowerLimit || goods.minOrderAmount || 0
			};
			state.cartGoodsList = [data, ...cartGoodsList]; 
			uni.setStorageSync('cartGoodsList', [data, ...cartGoodsList]);
			return true;
		}
	},
	deletedAllCartGoods(state,goodsList) {//删除购物车所有商品
		let cartGoodsList = goodsList || [];
		state.cartGoodsList = cartGoodsList;
		uni.setStorageSync('cartGoodsList', cartGoodsList);
	},
	deletedCartGoods(state,goods) {//删除购物车该商品
		let cartGoodsList = state.cartGoodsList || [];
		if (cartGoodsList.findIndex(item=>item.id == goods.id)<0) return false;
		else {
			cartGoodsList.splice(cartGoodsList.findIndex(item=>item.id == goods.id),1);
			state.cartGoodsList = cartGoodsList;
			uni.setStorageSync('cartGoodsList', cartGoodsList);
			return true;
		}
	},
	updateCartGoodsData(state,goods) {//更新购物车该商品属性
		let cartGoodsList = state.cartGoodsList || [];
		if (cartGoodsList.findIndex(item=>item.id == goods.id)<0) return false;
		else {
			let data = {
				checked: goods.checked || false,
				number: goods.number,
				isDelete: goods.isDelete || 2
			};
			cartGoodsList[cartGoodsList.findIndex(item=>item.id == goods.id)] = {...cartGoodsList[cartGoodsList.findIndex(item=>item.id == goods.id)],...data};
			state.cartGoodsList = cartGoodsList;
			uni.setStorageSync('cartGoodsList', cartGoodsList);
			return true;
		}
	},
	refreshCartGoodsData(state,data) {
		let cartGoodsList = state.cartGoodsList || [];
		state.cartGoodsList = [...cartGoodsList];
		uni.setStorageSync('cartGoodsList', [...cartGoodsList]);
	}
};
